unit Unit13;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ZAbstractRODataset, ZAbstractDataset,
  ZDataset, ExtCtrls, StdCtrls, DBCtrls, ComCtrls;

type
  TForm13 = class(TForm)
    DataSource1: TDataSource;
    ZQuery1: TZQuery;
    DBGrid1: TDBGrid;
    Panel1: TPanel;
    DateTimePicker1: TDateTimePicker;
    Label1: TLabel;
    DataSource2: TDataSource;
    ZQuery2: TZQuery;
    DBLookupComboBox1: TDBLookupComboBox;
    Label2: TLabel;
    DBLookupComboBox2: TDBLookupComboBox;
    DataSource3: TDataSource;
    ZQuery3: TZQuery;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form13: TForm13;

implementation

uses
  Unit5;
  
{$R *.dfm}

procedure TForm13.FormActivate(Sender: TObject);
begin
  with ZQuery1 do begin
    SQL.Clear;
    SQL.Add('SELECT * FROM result');
    Open;
  end;
  With Form13.DBGrid1 do begin
    Columns[0].FieldName := 'rnum';
    Columns[1].FieldName := 'rdate';
    Columns[2].FieldName := 'rtime';
    Columns[3].FieldName := 'outlet';
    Columns[4].FieldName := 'last_name';
    Columns[5].FieldName := 'rname';
    Columns[6].FieldName := 'rtest_name';
    Columns[7].FieldName := 'rball';
    Columns[8].FieldName := 'lost_time';
    Columns[9].FieldName := 'qlost';
  end;
  With ZQuery2 do begin
    SQL.Clear;
    SQL.Add('SELECT * FROM users');
    Open;
  end;
  Form13.DBLookupComboBox1.KeyField := 'login';
  With ZQuery3 do begin
    SQL.Clear;
    SQL.Add('SELECT * FROM `group`');
    Open;
  end;
  Form13.DBLookupComboBox2.KeyField := 'gname';

end;

procedure TForm13.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TForm13.Button1Click(Sender: TObject);
var
  query : string;
begin
  if DateToStr(Form13.DateTimePicker1.Date) <> '' then query := 'SELECT * FROM result WHERE rdate = "' + DateToStr(Form13.DateTimePicker1.) + '"';
  {if Form13.DBLookupComboBox1.Text = '' then query := 'SELECT * FROM result WHERE outlet = "' + Form13.DBLookupComboBox2.Text + '"';
  if Form13.DBLookupComboBox2.Text = '' then query := 'SELECT * FROM result WHERE last_name = "' + Form13.DBLookupComboBox1.Text + '"';
  if (Form13.DBLookupComboBox1.Text = '') and (Form13.DBLookupComboBox2.Text = '') then query := 'SELECT * FROM result';
  if (Form13.DBLookupComboBox1.Text <> '') and (Form13.DBLookupComboBox2.Text <> '') then query := 'SELECT * FROM result WHERE last_name = "' + Form13.DBLookupComboBox1.Text + '" AND outlet = "' + Form13.DBLookupComboBox2.Text + '"';}
  With ZQuery1 do begin
    close;
    SQL.Clear;
    SQL.Add(query);
    Open;
  end;
  Form13.DBGrid1.Refresh;
end;

end.
